package com.pulaien.shop.controller;

import com.pulaien.common.core.controller.BaseController;
import com.pulaien.common.core.domain.AjaxResult;
import com.pulaien.common.utils.ConstantsUtil;
import com.pulaien.system.domain.ConfigCheckProject;
import com.pulaien.system.domain.ConfigPayProject;
import com.pulaien.system.service.IConfigCheckProjectService;
import com.pulaien.system.service.IConfigPayProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 收费项目配置Controller
 *
 * @author pulaien
 */
@RestController
@RequestMapping("/shop/configPayProject")
@Api(tags = "商城端检品选项费用配置", description = "收费项目配置")
public class ShopPayProjectController extends BaseController {
    @Autowired
    private IConfigPayProjectService configPayProjectService;

    @Autowired
    private IConfigCheckProjectService configCheckProjectService;


    @ApiOperation(value = "获取收费项目的下拉框")
    @RequestMapping(value = "/getCheckPayProject", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult getCheckPayProject(HttpServletRequest request) {
        String lang = request.getHeader("Accept-Language");
        List<ConfigCheckProject> list = configCheckProjectService.listForCheck();
        List<Map<String, Object>> mapList = new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            for (ConfigCheckProject payProject : list) {
                Map<String, Object> map = new HashMap<>();
                map.put("checkPayId", payProject.getId());
                map.put("payPrice", payProject.getPayPrice());
                map.put("payNameJp", payProject.getPayPrice());
                map.put("payNameEn", payProject.getPayPrice());
                map.put("payName", payProject.getPayName());
                if (StringUtils.equals(lang, ConstantsUtil.LANG_EN)){
                    map.put("name", payProject.getPayNameEn());
                }else if (StringUtils.equals(lang,ConstantsUtil.LANG_JA)){
                    map.put("name", payProject.getPayNameJp());
                }else{
                    map.put("name", payProject.getPayName());
                }

                mapList.add(map);
            }
        }

        return AjaxResult.success(mapList);
    }
}
